********Table L.1 - Indonesia********

*Load data
cd "$reploc/data/created_data"
use indo_full, clear


sort pidlink ifls
foreach var of varlist rbuc_garefined rbuc grbrprovAvg_lam0co3 grbrprovSD_lam0co3 inflation{
gen `var'dif=`var'-`var'[_n-1] if ifls==5 & pidlink==pidlink[_n-1]
} 

*Do these results for primary sample
egen coh_prov_clust=group(biryear_impl birprov_impl)

gen primarysample1=0
replace primarysample1=1 if rbuc_garefineddif!=. & grbrprovAvg_lam0co3dif!=. & grbrprovSD_lam0co3dif!=. & inflationdif!=. &  biryear_impl>=1961 & coh_prov_clust!=.

egen primarysample=total(primarysample1), by(pidlink)

keep if primarysample==1

*Annualized growth rate in state of residence, assume 0 in 2007
gen grexannualized=0 if ifls==4
ereplace grexannualized=rowmean(grex2008 grex2009 grex2010 grex2011 grex2012 grex2013 grex2014) if ifls==5

gen provex=Prov2007  if ifls==4
replace provex=Prov2014  if ifls==5

*Normalize
gen income_ia_use=income_ia/1000000

*Generate log income
gen loginc_ia_use=log(income_ia_use)

local welfarevars loginc_ia_use unemployed swlowlivingstandard swlowfoodconsumption

keep ifls pidlink inflation imp_age panel married hhsize hhsize_sq Eddum* `welfarevars' grexannualized biryear_impl birprov_impl

reshape wide imp_age married hhsize hhsize_sq Eddum1 Eddum2 Eddum3 Eddum4  `welfarevars' inflation grexannualized, i(pidlink) j(ifls)

local varlist1 imp_age married hhsize hhsize_sq Eddum1 Eddum2 Eddum3 Eddum4  `welfarevars' inflation grexannualized

foreach var in `varlist1'  {
gen `var'dif=.
replace `var'dif=`var'5-`var'4
}

egen coh_prov_clust=group(biryear_impl birprov_impl)

*Regressions
local usei grex

cd "$reploc/results"	

local i=0
foreach var in `welfarevars' {

reg `var'dif `usei'annualizeddif marrieddif hhsizedif hhsize_sqdif Eddum*dif, vce(cluster coh_prov_clust)

if `i'==0 {
outreg2 using TableL1_Indonesia.tex, replace label ctitle(`var')  keep(`usei'annualizeddif) stats(coef se)  sortvar(`usei'annualizeddif) dec(2) sdec(2)
}

if `i'>0 {
outreg2 using TableL1_Indonesia.tex, append label ctitle(`var')  keep(`usei'annualizeddif) stats(coef se)  sortvar(`usei'annualizeddif) dec(2) sdec(2)
}

local i=`i'+1

}


